const mongoose = require('mongoose');

const BillSchema = new mongoose.Schema(
   {
      fromGroup: {
         type: mongoose.Types.ObjectId,
         ref: 'Group',
         required: true,
      },
      payStatus: {
         type: String,
         enum: ['to_be_collected', 'collected'], // 未收款 已收款
         default: 'to_be_collected',
      },
      createdBy: {
         type: mongoose.Types.ObjectId,
         ref: 'User',
      },
      bill_desc: {
         type: String,
         default: '',
      },
      category: {
         type: mongoose.Types.ObjectId,
         ref: 'Category',
         required: true,
      },
      account: {
         type: Number,
         required: true,
      },
      members: {
         type: [mongoose.Types.ObjectId],
         ref: 'User',
         required: true,
      },
      mode: {
         type: String,
         enum: ['average', 'separated'],
         default: 'average',
      },
   },
   {
      timestamps: true,
   }
);

module.exports = mongoose.model('Bill', BillSchema);
